package househomework;

import java.util.Arrays;
import java.util.Scanner;

public class HouseService {

    House[] houses;
    int houseNum = 0;
    public HouseService(){
        houses =new House[3];
    }

    public  boolean add(House house){

        if (houseNum == houses.length){
            System.out.println("数组满了。。");
            return false;
        }
        houses[houseNum++] = house;
        houses[houseNum-1].setHouseId(houseNum);
        return true;

    }
    public House[] checkHouse(){
        return houses;
    }

    public House findHouse(int houseId){
        for (int i=0;i< houseNum;i++){
            if ( houseId==houses[i].getHouseId()){
                return houses[i];
            }
        }
        return null;
    }

    public boolean deleteHouse(int houseId){
        Scanner scan =new Scanner(System.in);
        for (int i=0;i< houseNum;i++){
            if ( houses[i].getHouseId()==houseId){
                System.out.println("请确认是否删除（Y/N）:小心选择：");
                System.out.println("请输入你的选择（Y/N）");
                String YorN = scan.next();
                if ("Y".equalsIgnoreCase(YorN)){
                    houses[i]=houses[houses.length-1];
                    houses= Arrays.copyOf(houses,houses.length-1);
                    houseNum--;
                    return true;

                }
            }
        }
        return false;
    }

}
